package cn.tedu.Reader;

import java.io.*;

/**
 * Date��2022��01��
 * Author����Sir
 * Name�� JavaSE-API
 * Content:
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos  = new FileOutputStream("demo.txt");
        //这里使用的字符编码为UTF-8
        OutputStreamWriter writer = new OutputStreamWriter(fos,"gbk");
        String str = "大家好!";//UTF-8中文为3个字节，英文符号占1个字节
        writer.write(str);//写出后该文件大小应该为10字节
        writer.close();

        FileInputStream fis = new FileInputStream("demo.txt");
        /*
         *  这里设置了字符编码为GBK
         *  之后再通过ISR读取demo.txt文件时
         *  就使用GBK编码读取字符了
         */
        InputStreamReader reader = new InputStreamReader(fis,"utf-8");
        int c = -1;
        while((c = reader.read()) != -1){
            System.out.print((char)c);
        }
        reader.close();
    }
}
